<?php

$bIgnorePHPVersion= false; // Ignore PHP version //

$bError= false; // a flag to indicate if an error occured


$sEcho.= '<H2> ShopWindow Client status </H2>';
$sEcho.= 'v2.000 <br />';

$sEcho.= '<ul>';





# PHP version
$sEcho.= '<li>PHP5 compatible: ';
$aVarNums= explode('.', phpversion());

if ( $aVarNums[0] >= 5 && $aVarNums[1] >= 2 ) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$sEcho.= '<span style="color:red; font-weight:bold;">NO</span>';
	
	if ( ($aVarNums[0] >= 5 && $aVarNums[1] < 1) || $aVarNums[0] < 5 ) {
		$bError= true;
		$sEcho.= '<span style="color:grey; font:10px;"> ( Your PHP v'.phpversion().' is too old. You need at least PHP v5.1 ) </span>';
	}
	else {
		if (!$bIgnorePHPVersion) {
			$bError= true;
			$sEcho.= '<span style="color:grey; font:10px;"> ( Your version of PHP (v'.phpversion().') is out of date and may contain bugs that prevents this software from working - please reference <a href="http://www.shopwindowforum.com/showthread.php?t=791">http://www.shopwindowforum.com/showthread.php?t=791</a> for more information. ) </span>';
		}
	}
}
$sEcho.= '</li>';


# Soap Enabled
$sEcho.= '<li>Soap Installed and Enabled: ';
$aVarNums= explode('.', phpversion());

if ( class_exists('SoapClient') ) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$sEcho.= '<span style="color:red; font-weight:bold;">NO - Please recompile PHP on your server with the Soap extension enabled</span>';
	$bError= true;
}
$sEcho.= '</li>';


# WSDL access
$sEcho.= '<li>WSDL accessible: ';

$aUrlParts = parse_url(API_WSDL);	

$sRequest = "HEAD ".$aUrlParts['path'].'?'.$aUrlParts['query']." HTTP/1.1\r\n";
$sRequest .= "Host: ".$aUrlParts['host']."\r\n";
$sRequest .= "Connection: Close\r\n\r\n";

$rSocket = @fsockopen($aUrlParts['host'], 80);

@fwrite($rSocket, $sRequest);

// get first line and check HTTP response
if ( is_resource($rSocket) && strpos(trim(@fgets($rSocket)), '200 OK') !== false ) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$bError= true;
	$sEcho.= '<span style="color:red; font-weight:bold;">NO</span>';
	$sEcho.= '<span style="color:grey; font:10px;"> ( The WSDL file cannot be reached at '.API_WSDL.' ) </span>';
}

@fclose($rSocket);

$sEcho.= '</li>';


# API_USERID
$sEcho.= '<li>API_USERID set: ';
if (strlen(API_USERID)>0 && is_numeric(API_USERID)) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$bError= true;
	$sEcho.= '<span style="color:red; font-weight:bold;">NO</span>';
	$sEcho.= '<span style="color:grey; font:10px;"> ( Your User ID is not set correctly in file "constants.inc.php" ) </span>';
}
$sEcho.= '</li>';


# API_USERPASS
$sEcho.= '<li>API_USERPASS set: ';
if ( strlen(API_USERPASS)==48 ) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$bError= true;
	$sEcho.= '<span style="color:red; font-weight:bold;">NO</span>';
	$sEcho.= '<span style="color:grey; font:10px;"> ( Your User PASSWORD is not set correctly in file "constants.inc.php" ) </span>';
}
$sEcho.= '</li>';


# "templates_c" is writable
$sEcho.= '<li>Template folder writable: ';
$sTpPath= HOME_PATH.'smarty/templates_c/';
if (is_writable($sTpPath)) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$bError= true;
	$sEcho.= '<span style="color:red; font-weight:bold;">NO</span>';
	$sEcho.= '<span style="color:grey; font:10px;"> ( Please change the permissions on the folder "'.$sTpPath.'" to be writable ) </span>';
}
$sEcho.= '</li>';


# "cache" is writable
$sEcho.= '<li>Cache folder writable: ';
$sTpPath= HOME_PATH.'smarty/cache/';
if (is_writable($sTpPath)) {
	$sEcho.= '<span style="color:green; font-weight:bold;">YES</span>';
}
else {
	$bError= true;
	$sEcho.= '<span style="color:red; font-weight:bold;">NO</span>';
	$sEcho.= '<span style="color:grey; font:10px;"> ( Please change the permissions on the folder "'.$sTpPath.'" to writable ) </span>';
}
$sEcho.= '</li>';


$sEcho.= '<ul>';




// only print if error occured or manually requested
if ($bError===true || $_GET['debug']==1) {
	die($sEcho);
}


?>